repo: Add OSTREE_BOOTID override envvar for debugging
authorColin Walters <walters@verbum.org>
Tue, 19 Apr 2016 19:19:46 +0000 (15:19 -0400)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Mon, 2 May 2016 18:44:44 +0000 (18:44 +0000)
It's useful for test cases to be able to influence this.

Conflicts:
src/libostree/ostree-repo.c

Closes: #170
Approved by: jlebon

src/libostree/ostree-repo.c
tests/basic-test.sh
tests/libtest.sh

index d44aeabeefd9170591f5a8e87f16597e8d9bef62..a34e2ec163e9df0308df1187c7dd8922d8b67283 100644 (file)
@@ -2431,12 +2431,20 @@ ostree_repo_open (OstreeRepo    *self,
   /* We use a per-boot identifier to keep track of which file contents
    * possibly haven't been sync'd to disk.
    */
-  if (!g_file_get_contents ("/proc/sys/kernel/random/boot_id",
-                           &self->boot_id,
-                           NULL,
-                           error))
-    goto out;
-  g_strdelimit (self->boot_id, "\n", '\0');
+  { const char *env_bootid = getenv ("OSTREE_BOOTID");
+
+    if (env_bootid != NULL)
+      self->boot_id = g_strdup (env_bootid);
+    else
+      {
+        if (!g_file_get_contents ("/proc/sys/kernel/random/boot_id",
+                                  &self->boot_id,
+                                  NULL,
+                                  error))
+          goto out;
+        g_strdelimit (self->boot_id, "\n", '\0');
+      }
+  }
 
   if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (self->repodir), TRUE,
                        &self->repo_dir_fd, error))
index 2edb15d20b02b118b36cfc8317e29e41e764ed2c..b24779555b81e4bc7df85941a211bcf2135849b7 100755 (executable)
@@ -400,11 +400,24 @@ echo "ok disable cache checkout"
 cd ${test_tmpdir}
 rm checkout-test2 -rf
 $OSTREE checkout test2 checkout-test2
-if env OSTREE_REPO_TEST_ERROR=pre-commit $OSTREE commit -b test2 -s '' $test_tmpdir/checkout-test2 2>err.txt; then
+date > checkout-test2/date.txt
+rm repo/tmp/* -rf
+export TEST_BOOTID=3072029c-8b10-60d1-d31b-8422eeff9b42
+if env OSTREE_REPO_TEST_ERROR=pre-commit OSTREE_BOOTID=${TEST_BOOTID} \
+       $OSTREE commit -b test2 -s '' $test_tmpdir/checkout-test2 2>err.txt; then
     assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_PRE_COMMIT"
 fi
 assert_file_has_content err.txt OSTREE_REPO_TEST_ERROR_PRE_COMMIT
-echo "ok test error pre commit"
+found_staging=0
+for d in $(find repo/tmp/ -maxdepth 1 -type d); do
+    bn=$(basename $d)
+    if test ${bn##staging-} != ${bn}; then
+       assert_str_match "${bn}" "^staging-${TEST_BOOTID}-"
+       found_staging=1
+    fi
+done
+assert_streq "${found_staging}" 1
+echo "ok test error pre commit/bootid"
 
 # Whiteouts
 cd ${test_tmpdir}
index 0ce10a629799a964f91b8b40b3becf4d6ea99da9..4d403a93fa3a40530733ecb0f18d975eb3731368 100755 (executable)
@@ -86,6 +86,12 @@ assert_streq () {
     test "$1" = "$2" || (echo 1>&2 "$1 != $2"; exit 1)
 }
 
+assert_str_match () {
+    if ! echo "$1" | grep -E -q "$2"; then
+       (echo 1>&2 "$1 does not match regexp $2"; exit 1)
+    fi
+}
+
 assert_not_streq () {
     (! test "$1" = "$2") || (echo 1>&2 "$1 == $2"; exit 1)
 }